package aperturescience.types;

public class ActionEngine {
	
	public static JSONPatient run(JSONPatient patient, Action action){
		PatientState oldd = patient.getState();
		PatientState neww = action.getNewStates(oldd);
		patient.setState(neww);
		return patient;
	
//		try {
//			JSONArray patientStates = patient.getStates();
//			JSONArray newStates = action.getNewStates(patientStates);
//			JSONArray newStates = new JSONArray();
//			
//			//change affected states
//			for (int i=0; i<patientStates.length(); i++) {
//				String currentState = (String)patientStates.get(i);
//				if (action.has(currentState)) { //the currentState is being changed by the action
//					String changedState = action.getNewState(currentState);
//					for(int k=0; k<changedStates.length(); k++){
//						if( ! (changedStates.get(k)).equals("remove") )
//							newStates.put(changedStates.get(k));
//					}
//				}
//				else //the currentState is not being changed by the action
//					newStates.put(currentState);
//			}
//			
//			//add created states
//			JSONArray createdStates = action.getNewStates("create");
//			for(int k=0; k<createdStates.length(); k++)
//				newStates.put(createdStates.get(k));
//			
//			//replace the patient's states with the new array
//			patient.remove(JSONPatient.STATE);
//			patient.put(JSONPatient.STATE,newStates);
//			
//			return patient;
//		}
//		catch(JSONException e){
//			return null;
//		}
	}
}
